#!/usr/bin/php
<?php

#Full script execution timer start
$fstimer = explode( ' ', microtime() );
$fstimer = $fstimer[1] + $fstimer[0];

#open the config file
$ini_array = parse_ini_file("jrbackup.ini",true);
#print_r($ini_array);

#$config = (object)$ini_array;
#var_dump($config);

set_error_handler("ErrorHandler");

foreach($ini_array as $jobName => $jobVars)
{
  $backupdir = $jobVars['backupto'] . "/" . $jobName;
  $date = date('Ymd');
  $dow = date('l');
  $dnow = date('N');
  $dom = date('m');
  $wnum = date('W');
  $month = date('F');

  $logfile="/tmp/" . $date . "_" . $jobName . "_backup.log";
  $logerr="/tmp/" . $date . "_" . $jobName . "_errors.log";
  $tmpfile="/tmp/" . $date . "_" . $jobName . ".tmp";
  $dbgfile="/tmp/" . $date . "_" . $jobName .  "_debug.log";

  file_put_contents($logfile,'');
  file_put_contents($logerr,'');
  file_put_contents($tmpfile,'');
  file_put_contents($dbgfile,'');




  #Cleanup the files
  unlink($logfile);
  unlink($logerr);
  unlink($tmpfile);
  unlink($dbgfile);
  
}




#Full script execution timer stop
$fetimer = explode( ' ', microtime() );
$fetimer = $fetimer[1] + $fetimer[0];
echo round($fetimer - $fstimer,4);


// Functions

function dbgMsg($msg,$nl)
{
  $dbgstamp = date('H:i:s');

  if(!$nl)
  {
    $msg = "[$dbgstamp] " . $msg;
  } else {
    $msg = "[$dbgstamp] " . $msg . "\n";
  }

  file_put_contents($dbgfile,$msg,FILE_APPEND);
}

function errorHandler($errno, $errstr, $errfile, $errline)
{
  //Do something cool here
}

?>